package com.tjsiqi.controller;

import com.tjsiqi.beans.PageQuery;
import com.tjsiqi.beans.PageResult;
import com.tjsiqi.common.JsonData;
import com.tjsiqi.model.Contract;
import com.tjsiqi.service.SysContractService;
import com.tjsiqi.service.SysTreeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.tagext.PageData;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 该功能页已删除
 */
@Controller
@RequestMapping("/sys/contract")
public class SysContractController {

    @Resource
    private SysContractService sysContractService;
    @Resource
    private SysTreeService sysTreeService;

    @RequestMapping("/ajax6")
    @ResponseBody
    public List<String> ajax6(HttpServletResponse response, HttpServletRequest request) throws IOException{
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json,charset=utf-8");
        List<String> conCscName = sysContractService.findCscName();
        return conCscName;

    }

    @RequestMapping("/contract.page")
    public ModelAndView page() {
        return new ModelAndView("contract");
    }

    @RequestMapping("/list.json")
    @ResponseBody
    public JsonData list() {
        return JsonData.success(sysContractService.getAll());
    }

    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveContract(Contract param) {
        //sysDeptService.save(param);
        sysContractService.save(param);
        return JsonData.success();
    }


    @RequestMapping("/page.json")
    @ResponseBody
    public JsonData page(HttpServletResponse response, HttpServletRequest request, String conCscUnit, PageQuery pageQuery)throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html,charset=utf-8");
        String username = request.getParameter("conCscUnit");
        String conCscUnit1 =null;
        try {
            conCscUnit1=new String (conCscUnit.getBytes("iso-8859-1"),"utf8");
            if(conCscUnit1.equals("请选择施工单位") ){
                conCscUnit1 = null;
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        PageResult<Contract> result = sysContractService.getPage(conCscUnit1,pageQuery);
        return JsonData.success(result);
    }

}
